<?php 
$show_validator = true;
include TMPL_PATH.'public/header.phtml';
?>
<script type="text/javascript" src="/statics/xheditor/xheditor-zh-cn.min.js"></script>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
         <a href='<?php echo U('category/index', 'vid='. $vid);?>' ><em><?php echo $vocabulary_name;?>管理</em></a><span>|</span>
         <a href='javascript:;' class="on"><span><?php if(isset($cat) && $cat)echo'编辑';else echo'添加';?><?php echo $vocabulary_name;?></span></a>
    </div>
</div>
<script type="text/javascript"> 
<!--
	$(function(){
		$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
		<?php if($vid == 1){?>
		$("#modelid").formValidator({onshow:"请选择属性类型",onfocus:"请选择属性类型",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请选择属性类型"});
		<?php } ?>
		<?php 
			//	if(isset($languageList) && $languageList):
			//		foreach ($languageList as $language_id => $language_name):
			?>
				//	var language_name = "<? echo $language_name; ?>";
			//		var language_id = <?php echo $language_id;?>;
		//$("#catname_"+language_id).formValidator({onshow:"请输入<?php echo $vocabulary_name;?>"+language_name+"名称",onfocus:"请输入<?php echo $vocabulary_name;?>"+language_name+"名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请输入<?php echo $vocabulary_name;?>"+language_name+"名称"});
		$("#catname_1").formValidator({onshow:"请输入<?php echo $vocabulary_name;?>名称",onfocus:"请输入<?php echo $vocabulary_name;?>名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请输入<?php echo $vocabulary_name;?>名称"});
		<?php 
			//	endforeach;
		//	endif;
		?>
	})
//-->
</script>

<form name="myform" id="myform" action="__SELF__" method="post" enctype="multipart/form-data">
<div class="pad-10">
<div class="col-tab">
<ul class="tabBut cu-li">
<?php 
$langCount = 0;
if(isset($languageList) && $languageList){
		$langCount = count($languageList);
}
$langCount++;
?>
<li id="tab_setting_1" class="on" onclick="SwapTab('setting','on','',<?php echo $langCount;?>,1);">基本选项</li>
<?php 
	if(isset($languageList) && $languageList):
		$i = 1;
		foreach ($languageList as $language_id => $language_name):
			$i++;
	?>
<li id="tab_setting_<?php echo $i;?>" onclick="SwapTab('setting','on','',<?php echo $langCount;?>,<?php echo $i;?>);"><?php echo $language_name;?></li>
<?php 
		endforeach;
	endif;
	?>
</ul>
<div id="div_setting_1" class="contentList pad-10">
<table width="100%" class="table_form ">
<?php if($vid==1 || $vid == 2){?>
      <tr>
        <th width="200">上级分类：</th>
        <td>
		<select name="parentid" id="parentid"><option value='0'>≡ 作为一级分类 ≡</option>
		<?php echo $select_categorys;?>
		</select>		</td>
      </tr>
 <?php } ?>
<?php if($vid==1){?>
		<tr>
        <th width="200">筛选属性：</th>
        <td>
        <script type="text/javascript">
          var arr = new Array();
          var sel_filter_attr = "请选择筛选属性";
          <?php 
		  foreach ($modelList as $model_id => $model_name):
			if(is_array($attr_list[$model_id])):
		  ?>
            arr[<?php echo $model_id?>] = new Array();
            <?php foreach ($attr_list[$model_id] as $i => $attr):?>
            	<?php foreach ($attr as $attr_id => $attr_name):?>
                arr[<?php echo $model_id?>][<?php echo $i;?>] = ["<?php echo $attr_name?>", <?php echo $attr_id;?>];
              <?php endforeach;?>
            <?php endforeach;?>
          <?php 
			endif;
		  endforeach;
		  ?>

          function changeCat(obj)
          {
            var key = obj.value;
            var sel = window.ActiveXObject ? obj.parentNode.childNodes[4] : obj.parentNode.childNodes[5];
            sel.length = 0;
            sel.options[0] = new Option(sel_filter_attr, 0);
            if (arr[key] == undefined)
            {
              return;
            }
            for (var i= 0; i < arr[key].length ;i++ )
            {
              sel.options[i+1] = new Option(arr[key][i][0], arr[key][i][1]);
            }

          }

          </script>

         
          <table width="100%" id="tbody-attr" align="center">
          <?php if($filter_attr_id == 0):?>
            <tr>
              <td>   
                   <a href="javascript:;" onclick="addFilterAttr(this)">[+]</a> 
                   <select onChange="changeCat(this)"><option value="0">请选择商品类型</option>
          <?php 
				 	if (isset($modelList) && $modelList):
				 		foreach ($modelList as $key => $val):
							if(is_array($attr_list[$key])):
				 	?>
				 	<option value='<?php echo $key?>' <?php if(isset($cat['model_id']) && $key==$cat['model_id'])echo 'selected';?>><?php echo $val;?></option>
				 	<?php 
							endif;
				 		endforeach;
				 	endif;
				 	?>
                   </select>&nbsp;&nbsp;
                   <select name="filter_attr[]"><option value="0">请选择筛选属性</option></select><br />                   
              </td>
            </tr>
            <?php 
            elseif(isset($filter_attr_list) && $filter_attr_list):
            	foreach ($filter_attr_list as $k => $fattr_list):
            ?>
            <tr>
              <td>
                 <?php if($k==0):?>
                   <a href="javascript:;" onclick="addFilterAttr(this)">[+]</a>
                 <?php else:?>
                   <a href="javascript:;" onclick="removeFilterAttr(this)">[-]&nbsp;</a>
                 <?php endif;?>
                 <select onChange="changeCat(this)"><option value="0">请选择商品类型</option>
           <?php 
				 	if (isset($modelList) && $modelList):
				 		foreach ($modelList as $key => $val):
				 	?>
				 	<option value='<?php echo $key?>' <?php if(isset($fattr_list['model_id']) && $key==$fattr_list['model_id'])echo 'selected';?>><?php echo $val;?></option>
				 	<?php 
				 		endforeach;
				 	endif;
				 	?></select>&nbsp;&nbsp;
                 <select name="filter_attr[]"><option value="0">请选择筛选属性</option>
                 <?php foreach ($fattr_list['option'] as $attr_id => $attr_name):?>
                 <option value='<?php echo $attr_id;?>' <?php if(isset($fattr_list['attr_id']) && $attr_id==$fattr_list['attr_id'])echo 'selected';?>><?php echo $attr_name;?></option>
                 <?php 
                 		endforeach;
                 ?>
                 </select>
              </td>
            </tr>
            <?php 
            		endforeach;
            	endif;
            ?>
          </table>
				</td>
      </tr>
 <?php } ?>
      <tr class="hidden">
        <th>页面别名：</th>
        <td><input type="text" name="path_alias" id="path_alias" class="input-text" value="<?php echo isset($cat['path_alias']) ? $cat['path_alias'] : null;?>"/> <div class="infoShow">地址栏中展示的URL别名</div></td>
      </tr>
			<tr>
        <th><?php echo $vocabulary_name;?>图片：</th>
        <td><input type="file" name="upimage" id="upimage" value="" size="50" class="" /></td>
      </tr>
      <tr>
          <th><?php echo $vid==1?"广告":"选中"?>图片：</th>
        <td><input type="file" name="upimage_adv" id="upimage_adv" value="" size="50" class="" /></td>
      </tr>
	  <?php if($vid==1):?>
	  <tr>
        <th>分类属性列表：</th>
        <td>
		<?php 
			$categoryList = CategoryModel::getCategoryList(CategoryModel::TYPE_STYLE);
			if($categoryList):
				foreach ($categoryList as $category):
		?>
		<input type="checkbox" name="categoryId[]" <?php if(in_array($category['id'],$category_id)){echo 'checked';}?> value="<?php echo $category['id'];?>" /><?php echo $category['name'];?>
		<?php 
				endforeach;
			endif;
		?>
		</td>
      </tr>
	  <tr>
        <th>分类属性（颜色）列表：</th>
        <td>
		<?php 
			$categoryList = CategoryModel::getCategoryList(CategoryModel::TYPE_COLOUR);
			if($categoryList):
				foreach ($categoryList as $category):
		?>
		<input type="checkbox" name="colourId[]" <?php if(in_array($category['id'],$colour_id)){echo 'checked';}?> value="<?php echo $category['id'];?>" /><?php echo $category['name'];?>
		<?php 
				endforeach;
			endif;
		?>
		</td>
      </tr>
	  <?php endif;?>		
	  <tr class="hidden">
        <th>模板名称：</th>
        <td><input type="text" name="template" id="template" class="input-text" value="<?php echo isset($cat['template']) ? $cat['template'] : null;?>"/> <div class="infoShow">分类页使用的模板名称，不填为系统默认的模板，此功能用于前台各分类使用不同模板显示</div></td>
      </tr>
			<tr>
			<tr>
        <th>排序：</th>
        <td><input type="text" name="listorder" id="listorder" class="input-text" size="5" value="<?php echo isset($cat['listorder']) ? $cat['listorder'] : 0;?>"/></td>
      </tr>
      <tr>
     <th>是否显示：</th>
      <td>
	  <input type='radio' name='display' value='1' <?php if(!isset($cat['display']) || (isset($cat['display']) && $cat['display']==1))echo'checked';?>> 是&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='display' value='0' <?php if(isset($cat['display']) && $cat['display']==0)echo'checked';?>> 否</td>
    </tr>
    <th>是否3d显示：</th>
    <td>
        <input type='radio' name='is_3d' value='1' <?php if(isset($cat['is_3d']) && $cat['is_3d']==1)echo'checked';?>> 是&nbsp;&nbsp;&nbsp;&nbsp;
        <input type='radio' name='is_3d' value='0' <?php if($cat['is_3d']==0)echo'checked';?>> 否</td>
    </tr>
    <?php if(isset($cat['img']) && $cat['img']):?>
    <tr>
        <th><?php echo $vid==1?"分类":""?>图片：</th>
      <td><a title="放大" href="javascript:showImage('<?php echo $cat['img'];?>')"><img src="<?php echo $cat['img']?>" width="200" /></a></td>
    </tr>
    <?php endif;?>
    <?php if(isset($cat['adv_img']) && $cat['adv_img']):?>
    <tr>
        <th><?php echo $vid==1?"广告":"选中"?>图片：</th>
      <td><a title="放大" href="javascript:showImage('<?php echo $cat['adv_img'];?>')"><img src="<?php echo $cat['adv_img']?>" width="200" /></a></td>
    </tr>
    <?php endif;?>
</table>
</div>
<?php 
	if(isset($languageList) && $languageList):
		$i = 1;
		foreach ($languageList as $language_id => $language_name):
			$i++;
?>
<div id="div_setting_<?php echo $i;?>" class="contentList pad-10 hidden">
		<table width="100%" class="table_form ">
      <tr>
        <th><?php echo $vocabulary_name;?>名称：</th>
        <td><input type="text" name="category[<?php echo $language_id;?>][name]" id="catname_<?php echo $language_id;?>" class="input-text" value="<?php echo isset($cat['items'][$language_id]['name']) ? $cat['items'][$language_id]['name'] : null;?>"/></td>
      </tr>
      <tr>
        <th><?php echo $vocabulary_name;?>简介：</th>
        <td><textarea name="category[<?php echo $language_id;?>][summary]" style="width: 715px; height: 80px;"><?php echo isset($cat['items'][$language_id]['summary']) ? $cat['items'][$language_id]['summary'] : null;?></textarea></td>
      </tr>
      <tr>
        <th><?php echo $vocabulary_name;?>描述：</th>
        <td><textarea name="category[<?php echo $language_id;?>][description]" class="editor"><?php echo isset($cat['items'][$language_id]['description']) ? $cat['items'][$language_id]['description'] : null;?></textarea></td>
      </tr>
      <tr>
	      <th>网页标题：</th>
	      <td><textarea name='category[<?php echo $language_id;?>][meta_title]' style="width:50%;height:20px"><?php echo isset($cat['items'][$language_id]['meta_title']) ? $cat['items'][$language_id]['meta_title'] : null;?></textarea><div class="infoShow">针对搜索引擎设置的标题</div></td>
    </tr>
    <tr>
      <th>网页关键词：</th>
      <td><textarea name='category[<?php echo $language_id;?>][meta_keywords]' style="width:50%;height:40px"><?php echo isset($cat['items'][$language_id]['meta_keywords']) ? $cat['items'][$language_id]['meta_keywords'] : null;?></textarea><div class="infoShow">关键字中间用半角逗号隔开</div></td>
    </tr>
    <tr>
      <th>网页描述：</th>
      <td><textarea name='category[<?php echo $language_id;?>][meta_description]' style="width:50%;height:50px"><?php echo isset($cat['items'][$language_id]['meta_description']) ? $cat['items'][$language_id]['meta_description'] : null;?></textarea><div class="infoShow">针对搜索引擎设置的网页描述</div></td>
    </tr>
    <tr>
        <th><?php echo $vocabulary_name;?>图片：</th>
        <td><input type="file" name="cat_upimage_<?php echo $language_id;?>" id="" value="" size="50" class="" /></td>
    </tr>
    <tr>
        <th>广告图片：</th>
        <td><input type="file" name="cat_upimage_adv_<?php echo $language_id;?>" id="" value="" size="50" class="" /></td>
    </tr>
    <?php if(isset($cat['items'][$language_id]['items_img']) && $cat['items'][$language_id]['items_img']):?>
        <tr>
           <th>分类图片：</th>
           <td><a title="放大" href="javascript:showImage('<?php echo $cat['items'][$language_id]['items_img'];?>')"><img src="<?php echo $cat['items'][$language_id]['items_img']?>" width="200" /></a>
           <input type="hidden" name='category[<?php echo $language_id;?>][items_img]' value="<?php echo $cat['items'][$language_id]['items_img']?>" />
           </td>
        </tr>
    <?php endif;?>
    <?php if(isset($cat['items'][$language_id]['items_adv_img']) && $cat['items'][$language_id]['items_adv_img']):?>
        <tr>
           <th>广告图片：</th>
           <td><a title="放大" href="javascript:showImage('<?php echo $cat['items'][$language_id]['items_adv_img'];?>')"><img src="<?php echo $cat['items'][$language_id]['items_adv_img']?>" width="200" /></a>
           <input type="hidden" name='category[<?php echo $language_id;?>][items_adv_img]' value="<?php echo $cat['items'][$language_id]['items_adv_img']?>" />
           </td>
        </tr>
    <?php endif;?>
	</table>
</div>
	<?php 
		endforeach;
	endif;
	?>
 <div class="bk15"></div>
 <input type="hidden" name="img" value="<?php echo $cat['img']?>" />
 <input type="hidden" name="adv_img" value="<?php echo $cat['adv_img']?>" />
    <input name="dosubmit" type="submit" value="提交" class="button">
</div>
</div>
</form>
</body>
<script language="JavaScript">
var filter_attr_not_repeated = "筛选属性不可重复";
var filter_attr_not_selected = "请选择筛选属性";
/**
 * 新增一个筛选属性
 */
function addFilterAttr(obj)
{
  var src = obj.parentNode.parentNode;
  var tbl = document.getElementById('tbody-attr');

  var filterAttr = document.getElementsByName("filter_attr[]");

  if (filterAttr[filterAttr.length-1].selectedIndex == 0)
  {
    alert(filter_attr_not_selected);
    return false;
  }
  
  for (i = 0; i < filterAttr.length; i++)
  {
    for (j = i + 1; j <filterAttr.length; j++)
    {
      if (filterAttr.item(i).value == filterAttr.item(j).value)
      {
    	  alert(filter_attr_not_repeated);
    	  return false;
      } 
    } 
  }


  var row  = tbl.insertRow(tbl.rows.length);
  var cell = row.insertCell(-1);
  cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addFilterAttr)(.*)(\[)(\+)/i, "$1removeFilterAttr$3$4-");
  filterAttr[filterAttr.length-1].selectedIndex = 0;
}

/**
 * 删除一个筛选属性
 */
function removeFilterAttr(obj)
{
  var row = rowindex(obj.parentNode.parentNode);
  var tbl = document.getElementById('tbody-attr');

  tbl.deleteRow(row);
}
//-->
</script>
</html>